﻿// <copyright file="AddChild.xaml.cs" company="company"> 
// (C) 2010 . All rights reserved
// </copyright>
// <author>Lukasz Bartczak</author>

namespace SecretaryAppNav.Views
{
    using System;
    using System.Windows.Controls;
    using System.Windows.Navigation;
    using SecretaryAppNav.ClientWcfService;

    /// <summary>
    /// AddChild partial class
    /// </summary>
    public partial class AddChild : Page
    {
        /// <summary>
        /// Service proxy.
        /// </summary>
        private Service1Client client = new Service1Client();

        /// <summary>
        /// Initializes a new instance of the <see cref="AddChild"/> class.
        /// </summary>
        public AddChild()
        {
            InitializeComponent();
            this.client.AddChildAndOpiekunCompleted += new System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs>(this.Client_AddChildAndOpiekunCompleted);
            this.client.GetGroupsCompleted += new EventHandler<GetGroupsCompletedEventArgs>(this.Client_GetGroupsCompleted);
            this.client.GetGroupsAsync();
        }

        /// <summary>
        /// Handles the GetGroupsCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="SecretaryAppNav.ClientWcfService.GetGroupsCompletedEventArgs"/> instance containing the event data.</param>
        private void Client_GetGroupsCompleted(object sender, GetGroupsCompletedEventArgs e)
        {
            this.groups.ItemsSource = e.Result;
        }

        /// <summary>
        /// Handles the AddChildAndOpiekunCompleted event of the Client control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.ComponentModel.AsyncCompletedEventArgs"/> instance containing the event data.</param>
        private void Client_AddChildAndOpiekunCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
        {
        }

        /// <summary>
        /// Handles the Click event of the Button1 control - add child and opiekun.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void Button1_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.client.AddChildAndOpiekunAsync(this.tbDzFirstName.Value.ToString(), this.tbDzLastname.Value.ToString(), Convert.ToInt32(this.groups.SelectedValue.ToString()), this.opFirstname.Value.ToString(), this.opLastname.Value.ToString(), Convert.ToInt32(this.telNum.Value.ToString()));
            this.result.Content = "Dodano dziecko!";
        }
    }
}
